package com.masterclient.app.modules.shop;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.eoner.baselibrary.widget.CommonTabLayout;
import com.eoner.managerlibrary.router.AroutePath;
import com.masterclient.app.BaseActivity;
import com.masterclient.app.R;
import com.masterclient.app.modules.shop.adapter.CommonViewPagerAdapter;
import com.gyf.immersionbar.ImmersionBar;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @auther hxm
 * @date 2020/9/11.
 */
@Route(path = AroutePath.DEALER_SOLD_OUT_PRODUCT_ACTIVITY)
public class DealerSoldOutProductActivity extends BaseActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.dealer_product_manager_tab)
    CommonTabLayout dealerProductManagerTab;
    @BindView(R.id.dealer_product_manager_viewpager)
    ViewPager dealerProductManagerViewpager;
    @BindView(R.id.dealer_product_manager_bottom)
    View dealerProductManagerBottom;

    List<String> tabs = new ArrayList<>();
    List<Fragment> fragments = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dealer_product_manager);
        ButterKnife.bind(this);
        ImmersionBar.with(this).fitsSystemWindows(true).statusBarColor("#FF6809").init();

        tvTitle.setText("下架商品");
        dealerProductManagerBottom.setVisibility(View.GONE);
        tabs.add("经销品");
        tabs.add("轻创品");

        for (int i = 0; i < tabs.size(); i++) {
            dealerProductManagerTab.addTab(tabs.get(i), i == 0);
            fragments.add(DealerSoldOutProductFragment.newInstance(2,i + 2));
        }

        dealerProductManagerViewpager.setAdapter(new CommonViewPagerAdapter
                (getSupportFragmentManager(), fragments, tabs));
        dealerProductManagerViewpager.addOnPageChangeListener(new TabLayout.
                TabLayoutOnPageChangeListener(dealerProductManagerTab.getTabLayout()));
        dealerProductManagerTab.setupWithViewPager(dealerProductManagerViewpager);
    }

    public void setTabName(int index, String num, int status) {
        dealerProductManagerTab.refreshTab(index, tabs.get(index) + "(" + num + ")",
                dealerProductManagerViewpager.getCurrentItem()+2 == status);
    }

    @OnClick({R.id.dealer_product_manager_back})
    public void onViewClicked(View view) {
        if (view.getId() == R.id.dealer_product_manager_back) {
            finish();
        }
    }
}
